import pytest

from api.order_api.service_order_api.service_order_api import serviceOrderApi
from utils.utils import _assert


# 创建服务订单--》查询服务订单》--编辑服务订单》--》通过审核---》申请退款》---同意退款》

class TestServiceOrder03:

    @pytest.mark.run(order=1)
    def test01_order_create(self):
        """
        创建服务订单
        :return:
        """
        # 商店编号
        storeId = serviceOrderApi().store().json()['data']["records"][0].get("storeId")
        # 用户编号
        userId = serviceOrderApi().userID(storeId).json()['data']['records'][0].get("id")
        # 商品编号
        GoodsId = serviceOrderApi().storeGoods().json()['data']['records'][0].get("goodsId")
        # 服务价格
        price = serviceOrderApi().storeGoods().json()['data']['records'][0].get("price")
        # 发送接口请求
        global orderCode, id, response_
        response_ = serviceOrderApi().order_create(storeId=storeId, userId=userId, goodsId=GoodsId, Price=price)

        orderCode = response_.json()['data']['orderCode']
        id = response_.json()['data']['id']
        # 声明全局变量

        # 断言
        _assert(response_, 200, 0, True)

    @pytest.mark.run(order=2)
    def test02_all_order_search(self):
        """
        查询服务订单接口
        :return:
        """
        response = serviceOrderApi().all_order_search(orderCode=orderCode)
        _assert(response, 200, 0, True)

    @pytest.mark.run(order=3)
    def test03_order_editor(self):
        """
        编辑服务订单
        :return:
        """
        response = serviceOrderApi().order_editor(id)
        global data
        data = response.json()["data"]
        _assert(response, 200, 0, True)

    @pytest.mark.run(order=4)
    def test04_order_update(self):
        """
        确认编辑服务订单接口
        :return:  orderId,storeId,userId,Goodsid,price
        """
        orderId = response_.json()['data']['id']
        storeId = response_.json()['data']["storeId"]
        userId = response_.json()['data']['customerId']
        Goodsid = serviceOrderApi().storeGoods().json()['data']['records'][0].get("goodsId")
        price = response_.json()['data']['payPrice']
        response = serviceOrderApi().order_update(orderId=orderId, userId=userId, storeId=storeId, Goodsid=Goodsid,
                                                  price=price)
        _assert(response, 200, 0, True)

    @pytest.mark.run(order=5)
    def test05_order_details(self):
        """
        服务订单详情接口
        :return:
        """
        response = serviceOrderApi().order_details(id)
        _assert(response, 200, 0, True)

    @pytest.mark.run(order=6)
    def test06_order_pass(self):
        """
        服务订单通过审核接口
        :return:
        """
        response = serviceOrderApi().order_pass(id)
        _assert(response, 200, 0, True)

    @pytest.mark.run(order=7)
    def test07_order_applyRefund(self):
        """
        提出申请退款服务订单
        :return:
        """
        response = serviceOrderApi().order_applyRefund("好好学习，天天向上", id)
        _assert(response, 200, 0, True)

    @pytest.mark.run(order=8)
    def test08_order_refund(self):
        """
        拒绝退款
        :return:
        """
        response = serviceOrderApi().order_refund("好好学习，天天向上", id)
        _assert(response, 200, 0, True)

    @pytest.mark.run(order=9)
    def test04_order_orderDelete(self):
        """
        删除服务订单
        :return:
        """
        ""
        response = serviceOrderApi().order_orderDelete(orderId=id)
        _assert(response, 200, 0, True)